/**
 *  Config.cpp
 *
 *  Copyright (C) 2008  David Andrs <pda@jasnapaka.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <afx.h>
#include "Config.h"
#include "defs.h"
#include "reg.h"

LPCTSTR szEvent = _T("Event");
LPCTSTR szEventName = _T("EventName");
LPCTSTR szInstallDir = _T("InstallDir");

CConfig Config;


//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CConfig::CConfig() {
	memset(&Event, 0, sizeof(Event));

	FontSize = CONFIG_DEFAULT_FONT_SIZE;
	VOffset = 4;
	DisplayIcon = TRUE;
	ZeroHeight = FALSE;
}

CConfig::~CConfig() {
}

void CConfig::Save() {
	CRegistry reg(HKEY_CURRENT_USER, REG_KEY_APP);

	CString sDate;
	sDate.Format(_T("%d | %d | %d"), Event.wDay, Event.wMonth, Event.wYear);
	reg.Write(szEvent, sDate);
	reg.Write(szEventName, EventName);
}

void CConfig::Load() {
	CRegistry reg(HKEY_CURRENT_USER, REG_KEY_APP);

	InstallDir = reg.Read(szInstallDir, _T(""));

	CString sDate = reg.Read(szEvent, _T(""));
	if (!sDate.IsEmpty()) {
		int day, month, year;
		if (swscanf(sDate, _T("%d | %d | %d"), &day, &month, &year) == 3) {
			Event.wDay = day;
			Event.wMonth = month;
			Event.wYear = year;
		}
	}

	EventName = reg.Read(szEventName, _T(""));
}
